<!DOCTYPE html>
<!--
Copyright 2016 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/metrics/system_health/webview_startup_metric.html">
<link rel="import" href="/tracing/value/histogram_set.html">

<script>
'use strict';
tr.b.unittest.testSuite(function() {
  function makeTestModel() {
    return tr.c.TestUtils.newModel(function(model) {
      const mainThread = model.getOrCreateProcess(1).getOrCreateThread(2);
      mainThread.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
        cat: 'webview',
        title: 'WebViewStartupInterval',
        start: 200,
        duration: 42.0,
        cpuStart: 150,
        cpuDuration: 32.0
      }));
      mainThread.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
        cat: 'webview',
        title: 'WebViewBlankUrlLoadInterval',
        start: 250,
        duration: 27.0,
        cpuStart: 190,
        cpuDuration: 17.0
      }));
    });
  }

  test('webviewStartupMetric', function() {
    const histograms = new tr.v.HistogramSet();
    tr.metrics.sh.webviewStartupMetric(histograms, makeTestModel());
    assert.closeTo(42, histograms.getHistogramNamed(
        'webview_startup_wall_time').average, 1e-2);
    assert.closeTo(32, histograms.getHistogramNamed(
        'webview_startup_cpu_time').average, 1e-2);
    assert.closeTo(27, histograms.getHistogramNamed(
        'webview_url_load_wall_time').average, 1e-2);
    assert.closeTo(17, histograms.getHistogramNamed(
        'webview_url_load_cpu_time').average, 1e-2);
  });
});
</script>
